// components/person/person.js
const httprequest = require('../../../utils/http_utils.js')
var app = getApp();
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    phone: '', //手机号码
    info: '', //提示信息
    success: '', //成功提示
    error: '', //失败提示
    RowGuid: '',
    UserName: '', //用户名
    DisplayName: '', //用户姓名
    imgs: '', //性别照片
    title: '个人中心'
  },

  lifetimes: {
    // 生命周期函数，可以为函数，或一个在methods段中定义的方法名
    attached: function(options) {
      var that = this;
      console.log("options------" + app.globalData.globalphone + ',Mobile' + wx.getStorageSync("UserInfo").AppLogin.Mobile)
      that.data.RowGuid = wx.getStorageSync("UserInfo").AppLogin.RowGuid //获取缓存数据
      that.data.UserName = wx.getStorageSync('UserInfo').AppLogin.LoginID
      // console.log(JSON.stringify(wx.getStorageSync('UserInfo')) + "_____________用户缓存")

      if (app.globalData.globalphone != '' && app.globalData.globalphone != null && app.globalData.globalphone !=
        undefined) {
        that.setData({
          phone: app.globalData.globalphone
        })
      } else {
        that.setData({
          phone: wx.getStorageSync("UserInfo").AppLogin.Mobile
        })
      }
    },
    ready: function() {
      // app.globalData.template.tabbar("tabBar", 2, this)//0表示第一个tabbar 
      this.setData({
        DisplayName: wx.getStorageSync("UserInfo").AppLogin.DisplayName //获取用户姓名
      })
      if (wx.getStorageSync("UserInfo").AppLogin.Sex == 1) { //根据用户性别动态显示图片
        this.setData({
          imgs: "../../images/nan.png"
        })
      } else {
        this.setData({
          imgs: "../../images/nv.png"
        })
      }
    }
  },

  /**
   * 组件的方法列表
   */
  methods: {
    Eliminate: function() { //清除缓存
      console.log("清除缓存")
      this.setData({
        info: '功能暂未开通'
      })
    },

    dataUp: function() { //基础数据更新
      console.log("更新数据")
      this.setData({
        info: '功能暂未开通'
      })
    },
    JumpMima: function() { //修改密码跳转
      wx.redirectTo({
        url: '/pages/mima/mima',
      })
    },

    JumpPhone: function() { //修改手机号跳转
      wx.redirectTo({
        url: '/pages/phone/phone',
      })
    },

    goOut: function() { //退出登录
      var that = this;
      console.log(that.data.UserName + "_______________用户名")
      wx.showModal({
        title: '退出登录',
        content: '是否确定退出登录',
        success: function(res) {
          if (res.cancel) {} else {
            wx.request({
              url: httprequest.host + 'api/Mobile/MobileUserExitMobile',
              data: {
                "username": that.data.UserName,
                "UserGuid": wx.getStorageSync('UserInfo').AppLogin.RowGuid,
                "OpenID": wx.getStorageSync('openid')
              },
              header: {
                'content-type': "application/x-www-form-urlencoded",
                'UserName': that.data.UserName
              },
              method: 'GET',
              success: function(res) {
                console.log(JSON.stringify(res.data))
                if (res.data == "true" || res.data == true) {
                  wx.clearStorageSync();
                  that.setData({
                    success: '退出成功'
                  })
                  wx.redirectTo({
                    url: '/pages/login/login'
                  })
                }
              }
            })
          }
        }
      })
    },
  }
})